package com.changgou.order.mq.queue;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayQueueConfig {
    //创建queuel延时队列，会过期，过期后将数据发给Queue2
    @Bean
    public Queue orderDelayMessage() {
        return QueueBuilder
                .durable("orderDelayMessage")
                .withArgument("x-dead-letter-exchange", "orderListenerExchange") ///死信队列数据绑定到其他交换机中,过期之后，进入死性队列，死信队列，绑定交换机
                .withArgument("x-dead-letter-routing-key", "orderListenerQueue")
                .build();
    }

    //创建队列queue2
    @Bean
    public Queue orderListenerQueue() {
        return new Queue("orderListenerQueue",true);
    }

    //创建死信交换机
    @Bean
    public Exchange orderListenerExchange() {
        return new DirectExchange("orderListenerExchange");
    }

    //队列Queue2绑定Exchange
    @Bean
    public Binding orderListenerBinding(Queue orderListenerQueue, Exchange orderListenerExchange) {
        return BindingBuilder.bind(orderListenerQueue).to(orderListenerExchange).with("orderListenerQueue").noargs();
    }
}